using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Raptor.Client
{
  public partial class frmRegenerate : Form
  {
    private string m_RaptorUserName;

    public string RaptorUserName
    {
      get { return m_RaptorUserName; }
      set { m_RaptorUserName = value; }
    }

    private SqlConnection m_RaptorSqlConn;

    public SqlConnection RaptorSqlConn
    {
      get { return m_RaptorSqlConn; }
      set { m_RaptorSqlConn = value; }
    } 

    private bool m_ReasonSaved;

    public bool ReasonSaved
    {
      get { return m_ReasonSaved; }
      set { m_ReasonSaved = value; }
    }
	
    public frmRegenerate()
    {
      InitializeComponent();
    }

    private void frmRegenerate_Load(object sender, EventArgs e)
    {
      lblRegenDate.Text = DateTime.Now.ToString("d MMM yyyy, HH:mm:ss");
      lblRegenUser.Text = RaptorUserName;
    }

    private void btnCancel_Click(object sender, EventArgs e)
    {
      ReasonSaved = false;
      this.Close();
    }

    private void btnGenerate_Click(object sender, EventArgs e)
    {
      string sSQLString = "Insert Into Regenerate (Regenerate_Date, Regenerate_User, Regenerate_Reason) " +
                          "VALUES ('" + DateTime.Now.ToString() + "', '" + lblRegenUser.Text + "', '" + txtRegenerateReason.Text + "') select @@identity";

      if (txtRegenerateReason.Text.Length > 0 && txtRegenerateReason.Text.Trim() != String.Empty)
      {
        long regenerateId = 0;
        SqlCommand sqlComm = new SqlCommand(sSQLString, RaptorSqlConn);
        regenerateId = long.Parse(sqlComm.ExecuteScalar().ToString());

        if (regenerateId != 0)
        {
          ReasonSaved = true;
          this.Close();
        }
        else
        {
          ReasonSaved = false;
        }
      }
      else
      {
        ReasonSaved = false;
        txtRegenerateReason.Text = "";
        MessageBox.Show("You must specify a reason why you want to regenerate all previously generated objects to continue!");
      }
    }
  }
}